#include <iostream>

using std::cout;
using std::endl;

int func()
{
    cout << "int func()" << endl;
    return 10;
}

int func2()
{
    return 20;
}

int func3(int x)
{
    return x;
}

void test()
{
    typedef int a;
    typedef int(*pFunc)();//C++98给函数指针取别名
    /* typedef int(*)() pFunc; */
    /* using pFunc = int(*)();//C++11中给函数指针取别名 */

    //延迟调用的思想(C++中的多态就有延迟调用的思想)
    pFunc f = &func;//注册了回调函数
    cout << "hello" << endl;
    //...
    //...
    //...
    cout << "f() = " << f() << endl;//执行回调函数

    cout << endl;
    f = func2;
    cout << "f() = " << f() << endl;

    cout << endl;
    /* f = func3; //error, 函数指针f的类型与func3的类型是不匹配 */

}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

